# 展示每个分类的 IOU 条形图
import matplotlib.pyplot as plt
import numpy as np

# 数据准备
classes = [
    'wall', 'floor', 'cabinet', 'bed', 'chair', 'sofa', 'table', 'door',
    'window', 'bookshelf', 'picture', 'counter', 'desk', 'curtain',
    'refridgerator', 'shower curtain', 'toilet', 'sink', 'bathtub',
    'otherfurniture'
]
ious = [
    0.8687, 0.9579, 0.6646, 0.8710, 0.9229, 0.8511, 0.7493, 0.7066,
    0.7116, 0.8235, 0.3604, 0.6819, 0.6650, 0.7696, 0.6757, 0.7163,
    0.9164, 0.7011, 0.8619, 0.5649
]

# 创建图形
plt.figure(figsize=(16, 8))
plt.bar(classes, ious, color=plt.cm.tab20(np.arange(len(classes))))

# 添加灰色纵坐标刻度线（水平网格线）
plt.grid(axis='y', color='gray', linestyle='--', linewidth=0.5, alpha=0.7)

# 添加标签和标题
# plt.xlabel('Class Names', fontsize=12)
plt.ylabel('mIoU', fontsize=12)
plt.title('mIoU by Class on ScanNet20', fontsize=16)
plt.xticks(rotation=45, ha='right', fontsize=10)
plt.ylim(0, 1.0)

# 在条形上添加数值
for i, v in enumerate(ious):
    plt.text(i, v + 0.01, f"{v:.4f}", ha='center', fontsize=8)

plt.tight_layout()
plt.show()
# plt.savefig('mIoU_by_class.png', dpi=300, bbox_inches='tight')